package listbyorder.access201_300.test215;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/23 21:55
 */
public class Solution3 {

    // 方法三： 使用优先级队列创建一个大顶堆
    public int findKthLargest(int[] nums, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        for (int i = 0; i < nums.length; i++) {
            queue.add(nums[i]);
        }
        while (k != 1) {
            queue.poll();
            k--;
        }
        return queue.peek();
    }
}
